﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XmlAppliction
{
    public partial class configSetFrom : Form
    {
        string configXMLPath = Application.StartupPath + "\\config.xml";
        DataSet ds = new DataSet ();
        public configSetFrom()
        {
            InitializeComponent();
            
            ds.ReadXml(configXMLPath);
            textBox1.Text = ds.Tables[0].Rows[0]["saveXMLPath"].ToString();
            textBox2.Text = ds.Tables[0].Rows[0]["wordMubanPath"].ToString();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult Result = folderBrowserDialog1.ShowDialog();
            if (Result == DialogResult .OK &&  folderBrowserDialog1.SelectedPath != "")
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult Result = folderBrowserDialog1.ShowDialog();
            if (Result == DialogResult.OK && folderBrowserDialog1.SelectedPath != "")
            {
                textBox2.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void textBox1_DoubleClick(object sender, EventArgs e)
        {
            DialogResult Result = folderBrowserDialog1.ShowDialog();
            if (Result == DialogResult.OK && folderBrowserDialog1.SelectedPath != "")
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void textBox2_DoubleClick(object sender, EventArgs e)
        {
            DialogResult Result = folderBrowserDialog1.ShowDialog();
            if (Result == DialogResult.OK && folderBrowserDialog1.SelectedPath != "")
            {
                textBox2.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (File.Exists(configXMLPath)) File.Delete(configXMLPath);

            ds.Tables[0].Rows[0]["saveXMLPath"]=textBox1.Text ;
            ds.Tables[0].Rows[0]["wordMubanPath"]=textBox2.Text ;
            ds.WriteXml(configXMLPath);
            MessageBox.Show("保存成功！"); 
        }

        private void button4_Click(object sender, EventArgs e)
        { 
            textBox1.Text = Application.StartupPath + "\\CreateXMLs";
            textBox2.Text = Application.StartupPath + "\\muban"; 
        }
    }
}
